package com.ruoyi.project.business.gpiobiz.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.gpiobiz.entity.ControlGpioBiz;
import com.ruoyi.project.business.gpiobiz.request.ListControlGpioBizRequest;
import com.ruoyi.project.business.gpiobiz.request.AddControlGpioBizRequest;
import com.ruoyi.project.business.gpiobiz.response.ControlGpioBizResponse;
import com.ruoyi.project.business.gpiobiz.service.IControlGpioBizService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 设备引脚业务Controller
 * 
 * @author ${author}
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/business/gpiobiz")
public class ControlGpioBizController extends BaseController {
    @Autowired
    private IControlGpioBizService controlGpioBizService;

    /**
     * 查询设备引脚业务列表
     */
//    @PreAuthorize("@ss.hasPermi('business:gpiobiz:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListControlGpioBizRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<ControlGpioBizResponse> list = controlGpioBizService.selectControlGpioBizList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出设备引脚业务列表
     */
    @PreAuthorize("@ss.hasPermi('business:gpiobiz:export')")
    @Log(title = "设备引脚业务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListControlGpioBizRequest request) {
        Long tenantId = getTenantId();
        List<ControlGpioBizResponse> list = controlGpioBizService.selectControlGpioBizList(request, tenantId);
        ExcelUtil<ControlGpioBizResponse> util = new ExcelUtil<>(ControlGpioBizResponse.class);
        return util.exportExcel(list, "gpiobiz");
    }

    /**
     * 获取设备引脚业务详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:gpiobiz:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(controlGpioBizService.selectControlGpioBizById(id));
    }

    /**
     * 新增设备引脚业务
     */
    @PreAuthorize("@ss.hasPermi('business:gpiobiz:add')")
    @Log(title = "设备引脚业务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddControlGpioBizRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(controlGpioBizService.insertControlGpioBiz(request, operatorId, tenantId));
    }

    /**
     * 修改设备引脚业务
     */
    @PreAuthorize("@ss.hasPermi('business:gpiobiz:edit')")
    @Log(title = "设备引脚业务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ControlGpioBiz controlGpioBiz) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(controlGpioBizService.updateControlGpioBiz(controlGpioBiz, operatorId, tenantId));
    }

    /**
     * 删除设备引脚业务
     */
    @PreAuthorize("@ss.hasPermi('business:gpiobiz:remove')")
    @Log(title = "设备引脚业务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(controlGpioBizService.deleteControlGpioBizByIds(ids, operatorId, tenantId));
    }
}
